package com.example.chenjun.myapplication.mvp.presenter;

import com.example.chenjun.myapplication.bean.CookBean;
import com.example.chenjun.myapplication.mvp.contract.CookListContract;
import com.example.chenjun.myapplication.mvp.contract.LabelDetailContract;
import com.example.chenjun.myapplication.mvp.contract.SearchCookContract;
import com.example.chenjun.myapplication.mvp.model.CookModel;

import java.util.List;

public class CookListPresenter extends CookListContract.AbstractCookListPresenter {
    private LabelDetailPresenter mLabelDetailPresenter;
    private SearchCookPresenter mSearchCookPresenter;

    @Override
    public void setViewModel(CookListContract.CookListView view, CookModel model) {
        super.setViewModel(view, model);
        mLabelDetailPresenter = new LabelDetailPresenter();
        mSearchCookPresenter = new SearchCookPresenter();
        mLabelDetailPresenter.setViewModel(new LabelDetailContract.LabelDetailView() {
            @Override
            public void getLabelDetailSuccess(List<CookBean> list) {
                getView().getCookListSuccess(list);
            }

            @Override
            public void getLabelDetailFailed(Exception e) {
                getView().getCookListFailed(e);
            }
        }, model);
        mSearchCookPresenter.setViewModel(new SearchCookContract.SearchCookView() {
            @Override
            public void findSearchCookSuccess(List<CookBean> list) {
                getView().getCookListSuccess(list);
            }

            @Override
            public void findSearchCookFailed(Exception e) {
                getView().getCookListFailed(e);
            }
        }, model);
    }

    @Override
    public void searchCookList(String searchKey, int index, int size) {
        mSearchCookPresenter.searchCookPresenter(searchKey, index, size);
    }

    @Override
    public void getLabelCookList(String labelId, int index, int size) {
        mLabelDetailPresenter.getLabelDetail(labelId, index, size);
    }
}
